//
//  AboutProductViewController.m
//  QuickCure
//
//  Created by haoge on 16/9/10.
//  Copyright © 2016年 haoge. All rights reserved.
//

#import "AboutProductViewController.h"
#import <Masonry.h>
#import <SVProgressHUD.h>
@interface AboutProductViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,weak)UIImageView * imageView;

@property (nonatomic,weak)UITableView * tableView;

@property (nonatomic,weak)UIView *footView;

@property (nonatomic,weak)UIButton * telBtn;
@end

@implementation AboutProductViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.title = @"关于产品";
    
    [self creatUi];
    self.tableView.rowHeight = 25;
    self.tableView.scrollEnabled = NO;
    
    self.tableView.tableFooterView = [UIView new];
    
}

-(void)creatUi
{
    //创建Logo
    [self creatLogo];
    //创建一个tableView
    [self creatTableView];
    //创建一个View版本号及拨打号码
    [self creatView];
    
}
-(void)creatLogo
{
    //实例化Logo的图片
    UIImageView * imageView=  [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"product_img_logo_nor.png"]];
    
    [self.view addSubview:imageView];
    //约束
    [imageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(80);
        
        make.centerX.equalTo(self.view.mas_centerX);
        
        make.width.offset(67);
        
        make.height.offset(88);
    }];
    
    //实例化下面logo的图片
    UIImageView * imageView2 = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"product_text_logo_nor.png"]];
    
    self.imageView = imageView2;
    
    [self.view addSubview:imageView2];
    //Logo2的约束
    [imageView2 mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(imageView.mas_bottom);
        
        make.centerX.equalTo(self.view.mas_centerX);
        
        make.width.offset(83);
        
        make.height.offset(49);
        
    }];
    
    
}


//创建一个tableView
-(void)creatTableView
{
    //实例化一个tableView
    UITableView * tableView= [[UITableView alloc]init];
    //代理
    tableView.dataSource = self;
    
    tableView.delegate = self;
    
    self.tableView = tableView;
    
    [self.view addSubview:tableView];
    //设置tableView的约束
    [tableView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.equalTo(self.view);
        
        make.top.equalTo(self.imageView.mas_bottom).offset(50);
        
        make.bottom.equalTo(self.view).offset(-100);
    }];
}

//创建一个View
-(void)creatView
{    //实例化一个View
    
    UIView * footView = [[UIView alloc]init];
    
    self.footView = footView;
    
    [self.view addSubview:footView];
    //View的约束
    [footView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.bottom.equalTo(self.view);
        
        make.top.equalTo(self.tableView.mas_bottom);
        
    }];
    //拨打电话的Btn
    [self teBtn];
    
    //实例化一个Lable
    UILabel * lable = [[UILabel alloc]init];
    
    lable.text = @"Virsion : 1.4.0";
    //设置文字居中
    lable.textAlignment = NSTextAlignmentCenter;
    
    lable.textColor = [UIColor blueColor];
    //添加到View中
    [footView addSubview:lable];
    //设置约束
    [lable mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.top.equalTo(self.telBtn.mas_bottom).offset(5);
        
        make.height.offset(30);
        
        make.width.offset(150);
        
        make.centerX.equalTo(self.view.mas_centerX);
    }];
    
    
}

-(void)teBtn
{
    //实例化一个BUTTON
    UIButton * telBtn = [[UIButton alloc]init];
    
    [telBtn setTitle:@"联系电话:10086" forState:UIControlStateNormal];
    
    [telBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
    
    [telBtn addTarget:self action:@selector(telPhone) forControlEvents:UIControlEventTouchUpInside];
    
    self.telBtn = telBtn;
    
    //将Button添加到View中
    [self.footView addSubview:telBtn];
    //设置约束
    [telBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.right.equalTo(self.footView);
        
        make.top.equalTo(self.footView.top);
        
        make.height.offset(30);
        
    }];
    
}
//拨打电话
-(void)telPhone
{
    //显示弹框
    UIAlertController *alert = [UIAlertController alertControllerWithTitle:@"温馨提示" message:@"是否拨打电话：10086" preferredStyle:UIAlertControllerStyleAlert];
    //确定按钮
    UIAlertAction *sureAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
        
        [[UIApplication sharedApplication] openURL:[NSURL URLWithString:@"tel://10086"]];
    }];
    //取消按钮
    UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];
    
    [alert addAction:cancelAction];
    [alert addAction:sureAction];
    
    [self presentViewController:alert animated:YES completion:nil];
    
}

//用户协议
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    [SVProgressHUD showWithStatus:@"用户协议"];
    //设置两秒后结束用户协议
    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
        
        [SVProgressHUD dismiss];
        
    });
    
}


-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    //设置CELL
    UITableViewCell * cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault   reuseIdentifier:nil];
    
    cell.textLabel.text = @"用户协议";
    //设置图片
    cell.imageView.image = [UIImage imageNamed:@"product_img_icon_xieyi.png"];
    //设置cell右边箭头
    cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
    
    //字体大小
    cell.textLabel.textAlignment = 16;
    
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    return cell;
}

-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    
    return 45;
}


@end
